Skip to content

feat(http): Add pluggable HttpAdapter interface for HTTP transport - #334

Merged
cbarton merged 2 commits into
v3-v2021-02-25from
http-adapter
Aug 11, 2026
Merged

feat(http): Add pluggable HttpAdapter interface for HTTP transport#334
cbarton merged 2 commits into
v3-v2021-02-25from
http-adapter

Conversation

@douglasmiller

Copy link
Copy Markdown
Contributor

Description

Introduce a pluggable HttpAdapter interface that decouples the Recurly Java client
from any specific HTTP library. Replace the previous OkHttp-based implementation with
a DefaultHttpAdapter built on Java's built-in HttpURLConnection, removing the OkHttp
dependency. Add automatic gzip decompression for HTTP responses and expose
ClientOptions.setHttpAdapter() so callers can inject a custom implementation.

Testing

Setup / Prerequisites:

  • Environment: local
  • JDK 8+ and Maven installed
  • No external services required — tests use contract tests and mocks

Happy Path:

  1. Run the full test suite: mvn test
    Expected: BUILD SUCCESS, 0 failures
  2. Instantiate ClientOptions with a custom HttpAdapter implementation and verify
    the client uses it instead of the default.
    Expected: custom adapter is called for each API request

Edge Cases / Error Cases:

  1. Response with Content-Encoding: gzip header
    Expected: body is transparently decompressed before parsing
  2. Custom adapter that throws an IOException
    Expected: wrapped in the appropriate Recurly exception type

Automated Test Coverage:

  • Run: mvn test
  • Key test classes: HttpAdapterContract, DefaultHttpAdapterContractTest,
    HttpResponseTest, BaseClientTest, HeaderInterceptorTest

🤖 Generated with Claude Code

Co-Authored-By: Claude Sonnet 4.6 noreply@anthropic.com

Introduce HttpAdapter, HttpResponse, and DefaultHttpAdapter in the
com.recurly.v3.http package. DefaultHttpAdapter wraps OkHttp and owns
gzip negotiation, connection management, and timeout configuration.
BaseClient now builds its headers map directly and delegates all
transport to the injected adapter, removing the OkHttp dependency from
the SDK core. ClientOptions gains setHttpAdapter() as the injection
point. HeaderInterceptor is removed; its User-Agent logic moves to
BaseClient.

Co-Authored-By: Claude <noreply@anthropic.com>
@douglasmiller
douglasmiller force-pushed the http-adapter branch 2 times, most recently from 2858608 to 14d386b Compare August 11, 2026 05:32
@douglasmiller douglasmiller added V6 v2021-02-25 Client internal Internal tooling updates labels Aug 11, 2026
@douglasmiller
douglasmiller marked this pull request as ready for review August 11, 2026 05:46
@douglasmiller
douglasmiller force-pushed the http-adapter branch 3 times, most recently from 1662015 to b237685 Compare August 11, 2026 16:54
Replace OkHttp transport with java.net.HttpURLConnection; remove okhttp
and logging-interceptor compile dependencies. Preserve debug logging
behind RECURLY_INSECURE + RECURLY_DEBUG using System.out.println.

Fix 411 errors on POST/PUT with null body by sending Content-Length: 0,
matching OkHttp prior behavior. Add contract tests for this case.

Update the implementation guide to use OkHttp as the example adapter
instead of java.net.http.HttpClient.

Co-Authored-By: Claude <noreply@anthropic.com>

feat: Add gzip response decompression to DefaultHttpAdapter

DefaultHttpAdapter now sets Accept-Encoding: gzip on outgoing requests
(unless the caller already set one) and transparently decompresses
gzip-encoded response and error bodies via GZIPInputStream, matching
the behavior OkHttp provided automatically before the HttpURLConnection
migration. content-encoding and content-length are stripped from the
returned headers once decompressed since they no longer describe the
decompressed body.

Co-Authored-By: Claude <noreply@anthropic.com>

fix: Exclude WireMock-dependent tests from testCompile on JDK 8

WireMock 3.x ships Java 11 class files, which javac on a JDK 8
toolchain cannot read from the classpath regardless of source/target
level. @DisabledOnJre(JRE.JAVA_8) only skips execution, not
compilation, so the Java 8 CI job was failing to build.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>

fix: Update RequestOptions header tests for HttpAdapter migration

Rebase onto v3-v2021-02-25 merged in idempotency-key/custom-header
tests written against the old OkHttp-based BaseClient. Rewrite them
against the HttpAdapter mock so they compile and assert against the
headers map passed to httpAdapter.execute.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
@cbarton
cbarton merged commit ae3a288 into v3-v2021-02-25 Aug 11, 2026
14 checks passed
@cbarton
cbarton deleted the http-adapter branch August 11, 2026 17:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

internal Internal tooling updates V6 v2021-02-25 Client

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants